package com.xuecheng.manager_cms_client.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {

    //申明队列名称
    public static final String QUEUE_CMS_POSTPAGE = "queue_cms_postpage";
    //申明交换机名称
    public static final String  EX_ROUTING_CMS_POSTPAGE ="ex_routing_cms_postpage";

    @Value("${xuesheng.mq.queue}")
    public String queue_cms_postpage_name;

    @Value("${xuesheng.mq.routingKey}")
    public String routingKey;

    //声明交换机
    @Bean(EX_ROUTING_CMS_POSTPAGE)
    public Exchange EXCHANGE_TOPIC_INFORM(){
        return ExchangeBuilder.directExchange(EX_ROUTING_CMS_POSTPAGE).durable(true).build();
    }

    //声明队列
    @Bean(QUEUE_CMS_POSTPAGE)
    public Queue QUEUE_CMS_POSTPAGE(){
        return new Queue(queue_cms_postpage_name);
    }

    //绑定交换机和队列
    @Bean
    public Binding BINDING_QUEUE_INFORM_SMS(@Qualifier(QUEUE_CMS_POSTPAGE) Queue queue,@Qualifier(EX_ROUTING_CMS_POSTPAGE) Exchange exchange){
           return BindingBuilder.bind(queue).to(exchange).with(routingKey).noargs();
    }
}
